package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.request.*;
import com.ylyq.ylxx.service.IYlyqCoverMessageService;
import com.ylyq.ylxx.service.IYlyqCoverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 577
 * @className YlyqCoverController
 * @date 2020/10/29
 **/
@RestController
@RequestMapping("/cover")
@Api(description = "落地页相关接口")
public class YlyqCoverController {
    @Autowired
    private IYlyqCoverService IYlyqCoverService;
    @Autowired
    private IYlyqCoverMessageService IYlyqCoverMessageService;

    @PostMapping("/submit")
    @ApiOperation(value = "表单提交")
    public ResponseData submit(@RequestBody SaveYlyqCoverMessageRequest saveYlyqCoverMessageRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverMessageService.submit(saveYlyqCoverMessageRequest));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增落地页")
    public ResponseData save(@RequestBody SaveYlyqCover saveYlyqCover) {
        return new ResponseData(ResponseData.Result.SUCCESS,IYlyqCoverService.save(saveYlyqCover));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除落地页")
    public ResponseData delete(@RequestBody RemoveCoverRequest removeCoverRequest){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.delete(removeCoverRequest));
    }

    @PostMapping("/deleteTemplateCover")
    @ApiOperation(value = "删除模板落地页")
    public ResponseData deleteTemplateCover(@RequestParam String id){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.deleteTemplateCover(id));
    }

    @PostMapping("/copy")
    @ApiOperation(value = "复制落地页")
    public ResponseData copy(@RequestParam String id){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.copy(id));
    }

    @GetMapping("/getCover")
    @ApiOperation(value = "获取落地页列表")
    public ResponseData getCover(@RequestParam String pageMode) {
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.getCover(pageMode));
    }

    @GetMapping("/getTemplateCover")
    @ApiOperation(value = "获取模版落地页列表")
    public ResponseData getTemplateCover() {
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.getTemplateCover());
    }

    @GetMapping("/getCoverDetails")
    @ApiOperation(value = "获取落地页详情")
    public ResponseData getCoverDetails(@RequestParam String id) {
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.getCoverDetails(id));
    }

    @PostMapping("/publishCover")
    @ApiOperation(value = "创建第三方落地页站点")
    public ResponseData publishCover(@RequestBody CreateCoverRequest createCoverRequest){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.publishCover(createCoverRequest));
    }

    @PostMapping("getCount")
    @ApiOperation(value = "获取落地页关键指标数据")
    public ResponseData getCount(@RequestParam String id){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.getCount(id));
    }

    @PostMapping("updateVisitCount")
    @ApiOperation(value = "记录落地页关键指标数据")
    public ResponseData updateVisitCount(@RequestParam String id){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.updateVisitCount(id));
    }

    @PostMapping("/updateCover")
    @ApiOperation(value = "落地页设置为模板落地页")
    public ResponseData updateCover(@RequestParam String id){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.updateCover(id));
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新落地页")
    public ResponseData update(@RequestBody UpdateCoverRequest updateCoverRequest){
        System.out.println(updateCoverRequest+"=================================");
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.updateById(updateCoverRequest));
    }


    @PostMapping("/useTemplateCover")
    @ApiOperation(value = "使用模板落地页")
    public ResponseData useTemplateCover(@RequestParam String id){
        return new ResponseData(ResponseData.Result.SUCCESS, IYlyqCoverService.useTemplateCover(id));
    }
}
